const webpackMerge = require('webpack-merge')

const baseWebpackConfig = require('./webpack.config.base')

const TerserWebpackPlugin = require('terser-webpack-plugin')

const webpackConfig = webpackMerge(baseWebpackConfig, {
    mode: 'production',
    devtool: 'eval-source-map',
    // 日志消息不传递出来
    stats: { children: false, warnings: false },
    optimization: {
        minimizer: [
            new TerserWebpackPlugin({
                terserOptions: {
                    warnings: false,
                    compress: {
                        // 保留警告？
                        warnings: false,
                        // 注释掉console.log？
                        drop_console: false,
                        // 清理无效代码？
                        dead_code: true,
                        // 删除debugger？
                        drop_debugger: true
                    },
                    output: {
                        // coments: false,
                        // 一行结构
                        beautify: false
                    },
                    mangle: true
                },
                parallel: true,
                sourceMap: false
            })
        ],
        splitChunks: {
            cacheGroups: {
                commons: {
                    name: 'commons',
                    chunks: 'initial',
                    minChunks: 3,
                    enforce: true
                }
            }
        }
    }
})

module.exports = webpackConfig